home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Loadstar 128 31
/
q31.d81
/
t.128 rle
< prev
next >
Wrap
Text File
|
2022-08-28
|
15KB
|
376 lines
1 2 8 R L E
Program by Bob Markland
Text by Bob Markland and Jeff Jones
For several months now RLE file compression has been used to cram up to
35% more programs and text onto each issue of LOADSTAR 64. To accomplish
this feat, Jeff Jones wrote a RLE -- Run Length Encoding -- utility,
published on LS #134.
Recently, Fender sent me Jeff's M/L source code along with a request to
make it work on the C-128. After some discussion, Fender and I agreed that
Jeff's program did everything he wanted it to, just not in 128 mode. So,
if you happen to subscribe to both LOADSTAR 64 and LOADSTAR 128 you will
find that 128 RLE works much the same as the C-64 version. (I have a real
aversion to re-inventing the wheel).
It will pay you, though, to become familiar with the following
information because BANK selection and differences in syntax are important
considerations on the C-128.
RLE is probably the most simple form of data compression next to
tokenization. It encodes repetitious data in only two bytes instead of up
to 128. RLE uses 4 bytes to encode 256 repeating bytes. In the code, the
first byte says how many consecutive bytes to expect. The second byte is
the actual byte that's being repeated. So 500 consecutive zeroes are coded
as 8 bytes instead of 500.
We could code up to 255 bytes, but it's more efficient to use only the
lower 128 numbers for repeating characters and the higher 127 for non-
repeating data. That way we don't have to have terminating flags, which
could possibly take up a lot of room if packing a big file. Thus, we have
a method by which the same byte that would flag repeating characters can be
used to flag an upcoming stream of non-repeating data. Streams of data
that don't repeat are preceded by a byte that is 128 plus the number of
non-repeating characters. The machine language easily spots literals and
then subtracts 128 from the code.
RLE works extremely well with fonts and most hi-res graphics. You
wouldn't want to use RLE on text unless it was full of consecutive spaces
or other repeating characters.
When used in conjunction with a screen switcher, RLE also works well
with program and game screens because, except for text screens like the one
you're reading now, most screens are full of consecutive spaces. Otherwise
they'd look too crowded. So most lend themselves to RLE. And even if the
screen doesn't pack well, the color memory of a text screen, even if it
varies from line to line, is usually laid out in such a way that the 1000
color bytes would pack down to only a few bytes. (See "Jeff's Tutorial on
Packing Screens" below).
Heavily dithered, "misty" and "busy" graphics, such as the type created
by Walt Harned, won't pack as well with RLE as they would with other forms
of compression, though they usually pack somewhat. Basically, the more
you see solid, unobstructed blocks of pixels or color, the more packable
that graphic is.
USING 128/RLE
-------------
There are three versions of 128/RLE on the disk:
FILENAME SYS LOCATION
--------------------------
128/RLE 0C00 3072
128/RLE 1300 4864
128/RLE 1C00 7168
NOTE: The source code to the routine (in EBUD format) is on the disk in
the file, "128/rle.s".
Load any one of these files into BANK 0, using:
BLOAD"128/RLE xxxx",Un,B0,Pnnnn
Which version above is the best one for you to use in a program? That
depends on the other ML programs or routines that you might want to use.
The first two ($0C00 and $1300) can be used as long as you aren't using
that area for other ML routines. The code at $1C00 requires that you open
up the graphic area ($1C00-$4000) with a GRAPHIC1 command.
FENDER'S NOTE: Since I program only in the 80-column mode on 128
computers, and invariably use CONTROL80, my programs always have
BASIC moved up to $4000 with a GRAPHIC1 command. This gives me the area
from $1C00 to $4000 for storing screens, data, or even machine language
routines like 128 REL.
In all the examples 128/RLE observes the following conventions. You
will note that they closely parallel BASIC 7.0 commands such as BLOAD and
BSAVE, with two major exceptions:
(1) You MUST follow the SYS command with a colon (:) rather than a comma.
(2) Unlike BASIC 7.0 there are no default values. You MUST supply ALL
drive (U), bank (B), and address (P) information, as shown in the examples
below.
SYSADDR[+N]:A,B$,C
ADDR[+N]: is the LOAD address of the M/L module plus N if applicable.
A, B$ and C are parameters. Parameters followed by $, such as B$, can be
supplied in string variables or literals within quotes or a combination of
the two, or any algorithm that creates a string. Numeric parameters can be
replaced with variables. NO QUOTES!!! You may also use any formula or
equation that generates a positive integer.
IMPORTANT NOTE: If you choose to use string variables, a combination of
string and literal text in quotes, or numeric variables, they MUST be
enclosed in parentheses ().
PACKING A FILE
--------------
SYSADDR+3:FILE$,U1,B1,P1:DEST$,U2,P2
This command will BLOAD a file to a buffer which you specify and pack
it, then SAVE the packed file under a new filename on any active drive,
with any LOAD address you desire.
ADDR+3 is the location of the pack file code.
FILE$ is the parameter where you plug in the filename. Since this isn't
an archive utility, and the packed files are meant to be used in memory,
the file must be small enough to fit into memory.
U1 is the device number of the source drive.
B1 is the bank where the source file will be loaded.
P1 is the area where the file will be examined by 128/RLE. When you pack
from disk file to disk file you will no doubt use the "RLE DISK TO DISK"
BASIC program included on this disk (and explained later) or your own
embellished version, which will probably be very short. So you can select
a buffer at any address in BANK 0, following the BASIC program.
This can be as low as 8192, which gives you room for a buffer of 223
blocks ($2000-$FEFF). Address 16384+ ($4000+) in BANK 1 is used as the
default output buffer. However, you can select any area of BANK 1, if you
find a need, by entering:
POKESYS+18,page.
For example: POKESYS+18,32 lowers the beginning of the buffer to 8192 in
BANK 1. If you find BANKing a little confusing, note that a graphic file
being examined at 8192 in BANK 0 and the output buffer at 8192 in BANK 1 do
not interfere with one another. You can even select a buffer directly
under 128/RLE.
DEST$ is the filename of your destination file.
U2 is the device number of your destination drive.
P2 is the desired LOAD address of the packed file.
UNPACKING FILES
---------------
Files can be unpacked in one of two ways. Packed files can be BLOADED
into a buffer by a routine in your program and then unpacked from one
location to another or they can be unpacked straight from disk with the
following command:
SYSADDR:FILE$,Un,Bn,Pn
FILE$ is the filename of the packed file.
Un is the device number of the drive containing the file you wish to
unpack.
Bn is the bank number to which the file is to be loaded (usually 1 or
0).
Pn is the desired LOAD address of the data. Making this parameter 0
will cause the unpack routine to respect the LOAD address the file was
created with.
COMPRESS RANGE OF MEMORY
------------------------
SYSADDR+6:B1,P1,P2,B2,P3
Here you can compress any range of memory and stash the compressed data
anywhere in RAM. This is useful if you already have data in memory which
you want to compress. Locations 253 and 254 or F% will report the end of
the output buffer, which you will need to know if you want to BSAVE the
data. If F% is a negative number (integer variables only go up to 32768),
you can derive the end from PEEK(254)*256+PEEK(253).
B1 is the bank where the decompressed data resides.
P1 is the beginning address of the decompressed data.
P2 is the ending address of the data to be packed PLUS 1 (+1).
B2